package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.DataGenerateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: hippo
 */
@RestController
@RequestMapping("/dataGenerate")
public class DataGenerateController {

    @Autowired
    private DataGenerateService dataGenerateService;

    @RequiresPermissions("dataGenerate:test")
    @PostMapping("/test")
    public JSONObject testGenerate(@RequestBody JSONObject data) throws Exception {
        return dataGenerateService.testGenerate(data);
    }

    @RequiresPermissions("dataGenerate:generateData")
    @PostMapping("/generateData")
    public JSONObject generateData(@RequestBody JSONObject data) throws Exception {
        return dataGenerateService.generateData(data);
    }

    @RequiresPermissions("dataGenerate:exportExcel")
    @PostMapping(value = "/exportExcel")
    public void exportExcel(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response) throws Exception {
        dataGenerateService.exportExcel(data, request, response);
    }
}
